<template>
    <div>
        <h3>用药管理</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">药品名称</td>
                    <td><input type="text" v-model="info.Yyname"></td>
                </tr>
                <tr>
                    <td align="right">科室</td>
                    <td><select v-model="info.Id">
                        <option value="">请选择</option>
                        <option  v-for="item in arr" :value="item.Id">{{ item.Ksname }}</option>
                    </select></td>
                </tr>
                <tr>
                    <td align="right">用药日期</td>
                    <td><input type="date" v-model="info.Yydate"></td>
                </tr>
                <tr>
                    <td align="right">病人姓名</td>
                    <td><input type="text" v-model="info.Brname"></td>
                </tr>
                <tr>
                    <td align="right">病房号码</td>
                    <td><input type="text" v-model="info.Bfhaom"></td>
                </tr>
                <tr>
                    <td align="right">用药状态</td>
                    <td>
                        <input type="radio" name="zt" :value="false" v-model="info.YyState">未开始
                        <input type="radio" name="zt" :value="true" v-model="info.YyState">已完成
                    </td>
                </tr>
                <tr>
                    <td align="right">配药医生</td>
                    <td><input type="text" v-model="info.Pyys"></td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td><input type="button" value="添加" class="btn btn-success" @click="ok"></td>
                </tr>
            </tbody>
        </table>
       
    </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted}from 'vue'
import axios from 'axios'; 
import moment from 'moment';
import{useRoute,useRouter}from 'vue-router'
const route=useRoute();
const router=useRouter();

let info:any=reactive({
  "Yyname": "",
  "Id": "",
  "Yydate": "",
  "Brname": "",
  "Bfhaom": "",
  "YyState": true,
  "Pyys": "",
})

let arr:any=ref([])

onMounted(()=>{
    bingYygl();
})
const bingYygl=()=>{
    axios({
        url:'/api/Yklx/GetListKsgl',
        method:'get'
    })
    .then((res)=>{
        arr.value=res.data
    })
}

const ok=()=>{
    if(info.Yyname==""){
        alert("药品名称不能为空")
        return;
    }
    if(info.Yydate==""){
        alert("用药日期不能为空")
        return;
    }
    if(info.Brname==""){
        alert("病人姓名不能为空")
        return;
    }
    if(info.Bfhaom==""){
        alert("病房号码不能为空")
        return;
    }
    if(info.Pyys==""){
        alert("配药医生不能为空")
        return;
    }
    axios({
        url:'/api/Yklx/AddYygl',
        method:'post',
        data:info,
    })
    .then((res)=>{
        console.log(res);
        if(res.data>0){
            alert('添加成功');
            router.push('/yyglList');
        }
        else
        {
            alert('添加失败');
            return;
        }
    })
}

</script>

<style scoped>

</style>